﻿using System.Collections.Generic;
using Yuebon.CMS.Dtos;
using Yuebon.CMS.IServices;
using Yuebon.CMS.Models;
using Yuebon.Commons;
using Yuebon.Commons.IoC;
using Yuebon.Commons.Models;

namespace Yuebon.CMS.Application
{
    public class ArticleNewsApp
    {

        IArticleNewsService service = IoCContainer.Resolve<IArticleNewsService>();
        IArticleCategoryService serviceArticleCategory = IoCContainer.Resolve<IArticleCategoryService>();

        /// <summary>
        /// 根据条件查询数据库,并返回对象集合(用于分页数据显示)
        /// </summary>
        /// <param name="condition">查询的条件</param>
        /// <param name="info">分页实体</param>
        /// <param name="fieldToSort">排序字段</param>
        /// <param name="desc">是否降序</param>
        /// <returns>指定对象的集合</returns>
        public List<ArticleNewsDto> FindWithPager(string where, PagerInfo pagerInfo, string fieldToSort, bool desc)
        {
            List<ArticleNews> list= service.FindWithPager(where, pagerInfo, fieldToSort, desc);
            List<ArticleNewsDto> resultList = new List<ArticleNewsDto>();
            foreach(ArticleNews item in list)
            {
                ArticleNewsDto articleNewsDto = new ArticleNewsDto();
                articleNewsDto.Id = item.Id;
                articleNewsDto.ImgUrl = item.ImgUrl;
                articleNewsDto.IsHot = item.IsHot;
                articleNewsDto.IsMsg = item.IsMsg;
                articleNewsDto.IsRed = item.IsRed;
                articleNewsDto.IsSlide = item.IsSlide;
                articleNewsDto.IsSys = item.IsSys;
                articleNewsDto.IsTop = item.IsTop;
                articleNewsDto.Author = item.Author;
                articleNewsDto.CategoryId = item.CategoryId;
                articleNewsDto.CategoryName = serviceArticleCategory.Get(item.CategoryId).Title;
                articleNewsDto.Click = item.Click;
                articleNewsDto.CompanyId = item.CompanyId;
                articleNewsDto.CreatorTime = item.CreatorTime;
                articleNewsDto.CreatorUserId = item.CreatorUserId;
                articleNewsDto.DeleteMark = item.DeleteMark;
                articleNewsDto.DeleteTime = item.DeleteTime;
                articleNewsDto.DeleteUserId = item.DeleteUserId;
                articleNewsDto.DeptId = item.DeptId;
                articleNewsDto.Description = item.Description;
                articleNewsDto.EnabledMark = item.EnabledMark;
                articleNewsDto.LastModifyTime = item.LastModifyTime;
                articleNewsDto.LastModifyUserId = item.LastModifyUserId;
                articleNewsDto.LikeCount = item.LikeCount;
                articleNewsDto.LinkUrl = item.LinkUrl;
                articleNewsDto.SeoDescription = item.SeoDescription;
                articleNewsDto.SeoKeywords = item.SeoKeywords;
                articleNewsDto.SeoTitle = item.SeoTitle;
                articleNewsDto.SortCode = item.SortCode;
                articleNewsDto.Source = item.Source;
                articleNewsDto.SubTitle = item.SubTitle;
                articleNewsDto.Tags = item.Tags;
                articleNewsDto.Title = item.Title;
                articleNewsDto.Zhaiyao = item.Zhaiyao;

                resultList.Add(articleNewsDto);
            }
            return resultList;
        }
    }
}
